﻿using Mirror;
using UnityEngine;
using Cinemachine;

namespace NetTest
{
    public class FollowCamera : NetworkBehaviour
    {
        private CinemachineVirtualCamera _virtualCamera;
        public CinemachineVirtualCamera MainCamera => _virtualCamera;
        public override void OnStartLocalPlayer()
        {
            base.OnStartLocalPlayer();
            _virtualCamera = GameObject.FindObjectOfType<CinemachineVirtualCamera>();

            if (_virtualCamera) 
            {
                _virtualCamera.Follow = transform;
                _virtualCamera.LookAt = transform;
            }
        }

        public override void OnStopLocalPlayer()
        {
            base.OnStopLocalPlayer();
            if (_virtualCamera != null) 
            {
                _virtualCamera.Follow = null;
                _virtualCamera.LookAt = null;
            }
        }
    }
}
